﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MINERP.DigitalOutput.AutoDistribute
{
    public partial class FrmPrinterAttribute : Form
    {
        //属性
        public FrmDigitalMain2 Frm = null;
        public MyControls.UserPrinter Printer = null;
        public FrmPrinterAttribute()
        {
            InitializeComponent();
        }

        private void FrmPrinterAttribute_Load(object sender, EventArgs e)
        {

        }

        public void SetOldAttribute(MyControls.UserPrinter printer)
        {
            this.Text = printer.PrinterName;
            txtLength.Text = printer.PrinterLength.ToString();
            txtWidth.Text = printer.PrinterWidth.ToString();
            txtSpeed.Text = printer.Speed.ToString();
            txtDpi.Text = printer.PrinterDPI.ToString();
            cbDisable.Checked = printer.IsDisable;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            double length = 0;
            double width = 0;
            double speed = 0;
            int dpi = 0;
            bool isDisable = false;
            try
            {
                length = Convert.ToDouble(txtLength.Text.Trim());
                if (length <= 0)
                {
                    ShowMsg("纸长必须为正数");
                    return;
                }
            }
            catch
            {
                ShowMsg("纸长必须为正数");
                return;
            }
            try
            {
                width = Convert.ToDouble(txtWidth.Text.Trim());
                if (width <= 0)
                {
                    ShowMsg("纸宽必须为正数");
                    return;
                }
            }
            catch
            {
                ShowMsg("纸宽必须为正数");
                return;
            }
            try
            {
                speed = Convert.ToDouble(txtSpeed.Text.Trim());
                if (speed <= 0)
                {
                    ShowMsg("纸宽必须为正数");
                    return;
                }
            }
            catch
            {
                ShowMsg("纸宽必须为正数");
                return;
            }
            try
            {
                dpi = Convert.ToInt32(txtDpi.Text.Trim());
                if (dpi <= 0)
                {
                    ShowMsg("DPI必须为正整数");
                    return;
                }
            }
            catch
            {
                ShowMsg("DPI必须为正整数");
                return;
            }
            if (cbDisable.Checked)
            {
                isDisable = true;
            }
            Printer.PrinterLength = length;
            Printer.PrinterWidth = width;
            Printer.Speed = speed;
            Printer.PrinterDPI = dpi;
            Printer.IsDisable = isDisable;
            Frm.SetPrinterAttribute(Printer);
            Cursor = Cursors.Default;
            this.Close();
        }
        private void ShowMsg(string msg)
        {
            MessageBox.Show(msg, "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            Cursor = Cursors.Default;
        }
    }
}
